package com.atguigu.srb.core.controller.admin;


import com.atguigu.srb.core.pojo.vo.BorrowDetailVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoApprovalVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoSearchVO;
import com.atguigu.srb.core.pojo.vo.BorrowInfoVO;
import com.atguigu.srb.core.service.BorrowInfoService;
import com.atguigu.srb.result.ResponseVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Atguigu
 * @since 2024-04-15
 */
@Api(tags = "管理员：借款信息接口")
@RestController
@RequestMapping("/admin/core/borrowInfo")
public class AdminBorrowInfoController {
    @Resource
    private BorrowInfoService borrowInfoService;

    // 1. 更新borrowInfo的状态 审核中->通过/拒绝
    // 2. 创建标的，状态为待发布
    @ApiOperation("借款信息的审批，是否创建`标的`")
    @PutMapping("approval/{borrowId}")
    public ResponseVo borrowInfoApproval(@PathVariable Long borrowId, @RequestBody BorrowInfoApprovalVO borrowInfoApprovalVO){
        borrowInfoApprovalVO.setBorrowInfoId(borrowId);
        borrowInfoService.borrowInfoApproval(borrowInfoApprovalVO);
        return ResponseVo.ok().message("审核通过");
    }

    @ApiOperation("获取借款详情VO")
    @GetMapping("/detail/{borrowInfoId}")
    public ResponseVo getBorrowDetail(@PathVariable Long borrowInfoId){
        BorrowDetailVO borrowDetailVO = borrowInfoService.getBorrowDetail(borrowInfoId);
        return ResponseVo.ok().addData("item",borrowDetailVO);
    }
    /**
     *  条件查询：
     *      姓名手机号作为关键字模糊查询
     *      借款金额区间查询
     *      借款期限区间查询
     *      还款方式查询
     *      资金用途查询
     *      年利化率区间查询
     *      状态查询
     *      申请时间区间查询
     * @param pageNum
     * @param pageSize
     */
    @ApiOperation("查询借款列表")
    @GetMapping("/{pageNum}/{pageSize}")
    public ResponseVo list(@PathVariable Integer pageNum,@PathVariable Integer pageSize,
                           BorrowInfoSearchVO borrowInfoSearchVO){
        Page<BorrowInfoVO> page = borrowInfoService.getBorrowInfoVOList(pageNum,pageSize,borrowInfoSearchVO);

        return ResponseVo.ok().addData("page",page);
    }
}

